const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');//清理 /dist 文件夹
const webpack = require('webpack');
module.exports = {
    mode:'development', //生产development 线上production
    entry: {//入口文件
        index:'./src/index.js',//首页
        offSheet:'./src/offSheet.js'//脱单
    },
    devtool: 'inline-source-map',
    devServer: {
        contentBase:path.resolve(__dirname,'dist'),
        host:'localhost',
        compress:true,
        port:8087
    },
     plugins: [//插件
         new CleanWebpackPlugin(),//new CleanWebpackPlugin(['dist']),
         new webpack.HotModuleReplacementPlugin(), //热更替插件
         new webpack.NamedModulesPlugin(),//热更替模块路径
         new webpack.ProvidePlugin({//提供插件
             $: 'jquery'
         }),
         new HtmlWebpackPlugin({
             template: './index.html',
             filename: 'index.html',
             chunks: ['index'],//需要那个js
        }),
         new HtmlWebpackPlugin({
             template: './offSheet.html',
             filename: 'offSheet.html',
             chunks: ['offSheet'],//需要那个js
         })
    ],
    output: { //出口文件
        // filename: 'bundle.js',
        filename: '[name][hash:8].js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: '/'
    },
     module: {
       rules: [
           {//js
               test: /\.js$/,
               use: {
                   loader: 'babel-loader',
                   options: {
                       presets: [ //预设
                           '@babel/preset-env'
                       ],
                       plugins:[
                           // 转es7的语法
                           ["@babel/plugin-proposal-decorators", { "legacy": true }],
                           ["@babel/plugin-proposal-class-properties", { "loose" : true }]
                       ]
                   }
               },
               exclude: /node_modules/
           },
         {//css
           test: /\.css$/,
                 use: [
                   'style-loader',
                   'css-loader'
                 ]
           },
            {//less
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
           },
           {//图片
            test: /\.(png|svg|jpg|gif)$/,
                use: [ 'file-loader']
          },
           {//字体
           test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: ['file-loader']
          },
           {//加载数据
           test: /\.(csv|tsv)$/,
                 use: ['csv-loader' ]
          },
           {//加载数据
             test: /\.xml$/,
                 use: ['xml-loader']
           }
         ]
       }
};